package com.hunttown.mes.dao;

import com.hunttown.common.dao.base.BaseDao;
import com.hunttown.common.domain.Query;
import com.hunttown.mes.domain.MesOrderMaterial;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Repository;

import java.util.List;

/**
 * created by wangjunfu on 2022-03-30 15:27:05
 */
@Repository
public class MesOrderMaterialDao extends BaseDao {
    private static final Logger logger = LoggerFactory.getLogger(MesOrderMaterialDao.class);

    public MesOrderMaterial insert(final MesOrderMaterial mesOrderMaterial) {
        insert("MesOrderMaterial.insert", mesOrderMaterial);
        return mesOrderMaterial;
    }

    public Boolean updateInfoById(final MesOrderMaterial mesOrderMaterial) {
        return update("MesOrderMaterial.updateInfoById", mesOrderMaterial) > 0;
    }

    public Boolean updateInfoByQuery(final Query query) {
        return update("MesOrderMaterial.updateInfoByQuery", query) > 0;
    }

    public MesOrderMaterial selectById(final Integer id, final Integer entId) {
        Query query = Query.noPage();
        query.put("id", id);
        query.put("entId", entId);
        return queryForObject("MesOrderMaterial.selectById", query);
    }

    public List<MesOrderMaterial> selectByQuery(final Query query) {
        return queryForList("MesOrderMaterial.selectByQuery", query);
    }

    public Long countByQuery(final Query query) {
        return queryForObject("MesOrderMaterial.countByQuery", query);
    }

    public Boolean deleteById(final Integer id, final Integer entId) {
        MesOrderMaterial mesOrderMaterial = new MesOrderMaterial();
        mesOrderMaterial.setDeleteFlag(1);
        mesOrderMaterial.setId(id);
        mesOrderMaterial.setEntId(entId);

        return update("MesOrderMaterial.updateInfoById", mesOrderMaterial) > 0;
    }

    //物理删除不可恢复，慎用！
    public Boolean deleteByIdForPhysical(final Integer id) {
        Query query = Query.noPage();
        query.put("id", id);
        return delete("MesOrderMaterial.deleteById", query) > 0;
    }
}